﻿using System;
using System.Collections.Generic;
using STeaL.Functional;

namespace STeaL.Algorithm {

  public static partial class IListExtensions {
#region insert
    public static int insert<T>(this IList<T> list, int position, T item) {
      list.Insert(position, item);
      return position;
    }

    public static int insert<T>(this IList<T> list, int position, int n, T item) {
      while (n-- > 0) list.Insert(position, item);
      return position;
    }

    public static int insert<T>(this IList<T> list, int position, IEnumerable<T> items) {
      int pos = position;
      foreach (T item in items) list.Insert(pos++, item);
      return position;
    }

#endregion
#region erase
    public static int erase<T>(this IList<T> list, int position) {
      list.RemoveAt(position);
      return position;
    }

    public static int erase<T>(this IList<T> list, int first, int last) {
      for (int n = first; n != last; ++n) list.RemoveAt(first);
      return first;
    }

#endregion
  }
}
